#include <iostream>
#include "Thread.hpp"
#include <unistd.h>

void func(int x)
{
    while (true)
    {
        std::cout << "x: " << x << std::endl;
        sleep(1);
    }
}

int main()
{
    // 1. 创建线程对象
    ThreadModel::MyThread<int> thread(func, 10);
    // 2. 创建线程
    thread.create();
    std::cout << "thread is running" << std::endl;
    sleep(3);

    // 3. 取消线程
    thread.cancel();
    std::cout << "cancel thread name: " << thread.name() << std::endl;
    sleep(2);

    // 4. 等待线程
    thread.join();
    std::cout << "join thread name: " << thread.name() << std::endl;
    sleep(2);

    std::cout << "---- " << std::endl;
    return 0;
}